Repository navigation
MDEV-41366 Check prefix key match in iterated partition index scan - #5821
Open
mariadb-YuchenPei wants to merge 1 commit into
Open
mariadb-YuchenPei wants to merge 1 commit into
mariadb-YuchenPei wants to merge 1 commit into
Conversation
|
|
mariadb-YuchenPei
force-pushed
the
bb-12.3-mdev-41366
branch
2 times, most recently
from
October 21, 2026 06:12
571304b to
81dcb00
Compare
…with prefix The idea of Case 2 in can_skip_merging_scans is that when partition column key prefix is fixed, and the infix that is also the "partition by range" column, we can scan each partition in order. To that end, we restrict access flags to exact accesses. Also reset m_unordered_prefix_len in the single-partition "unordered" scan case as it skips can_skip_merging_scans, which would otherwise leave a stale length for handle_unordered_prev. Also include HA_READ_KEY_OR_PREV in reverse_order flags, so that it can be considered and rejected for Case 2.
mariadb-YuchenPei
force-pushed
the
bb-12.3-mdev-41366
branch
from
October 21, 2026 06:37
81dcb00 to
b58f8cc
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The idea of Case 2 in can_skip_merging_scans is that when partition column key prefix is fixed, and the infix that is also the "partition by range" column, we can scan each partition in order. This relies on accurately returning EOF when a partition has no (more) matching rows. It is possible to have no more matching rows at the first index read of a partition in a non-exact access, in which case we need to check the prefix match to rule out false positives and return EOF correctly.
This change by itself would result in incomplete results, if Case 2 incorrectly determines the scan can iterate over partitions in order in AFTER_KEY and BEFORE_KEY reads. These reads when applied to a partition column key prefix, necessarily means seeking a different prefix value. This could result in false negatives. To that end, we strengthen the checks in Case 2 so that AFTER_KEY and BEFORE_KEY reads require both the prefix and the partitioned column itself in the keypart_map to ensure correctness.
For example, this check disqualifies the index_read_map call in an existing loose index scan testcase, causing the index scan to use both unordered (in read_range_first) and ordered.
Since we have to enumerate all flags, we include a fix of missing reverse_order for KEY_OR_PREV. The only known usecase is HANDLER ... READ which is not working correctly and due to be fixed in MDEV-41364. For consistency with other equally incorrect HANDLER cases involving other flags, we do not single out KEY_OR_PREV for special treatment (e.g. return false in can_skip_merging_scans).